<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");
require_once("moduleFunction.php");

$errMsg = "";
if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "save"){
	$errMsg .= moduleIns();
	$module = sxREQUEST("module");
	$description = sxREQUEST("description");
	$note = sxREQUEST("note");
	$doc_name = sxREQUEST("doc_name");
}else{
	$module = "";
	$description = "";
	$note = "";
	$doc_name = "";
}

//output HTML
$aOpz = array("kMenu"=>'pro.mod', "isReloadable"=>false);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
	function objFrmSave(){
		try{
			var objFrm = document.getElementById("objFrm");
			var objDA =  document.getElementById("module");
			var objDe =  document.getElementById("description");
			var objMessArea =  document.getElementById("messArea");
			var errMsg = "";
			if(objDe.value == ""){
				errMsg += "<?php echo _t("description missing.")?><br>";
				objDe.focus();
			}
			if(objDA.value == ""){
				errMsg += "<?php echo _t("name missing.")?><br>";
				objDA.focus();
			}
			if(errMsg == ""){
				objFrm.submit();
			}else{
				objMessArea.innerHTML = errMsg;
			}
		}catch(e){
			raiseError(e.description, "save new module");
		}			
	}
</script>
  
<?php
echo(bodyHTML($aOpz));
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
//form inserimento dati
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"moduleIns.php\" method=\"POST\" enctype=\"multipart/form-data\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");

//output comandi
$aCmd = array("insMD"=>array("pag"=>"javascript:objFrmSave()",
										"title"=>_t("save data"),
										"text"=>_t("save")
										),
					"back"=>array("pag"=>$objUser->getHistory(0,false),
										"title"=>'cancel operation',
										"text"=>'cancel'
										)
					);
echo(commandsHTML($aCmd));	
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" width=\"20%\" colspan='2'>"._t("Module")."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Name")."(*)</td>" .
			"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"module\" id=\"module\" maxlength=\"4\" value=\"$module\"></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Description")."(*)</td>" .
			"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"description\" id=\"description\" maxlength=\"80\" size=\"80\" value=\"".sxHE($description)."\"></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Note")."</td>" .
			"<td class=\"text01\"><textarea class=\"inpt01\" name=\"note\" id=\"note\" cols=\"80\" rows=\"8\">".sxHE($note)."</textarea></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Document")."</td>" .
			"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"doc_name\" id=\"doc_name\" maxlength=\"80\" size=\"32\" value=\"".sxHE($doc_name)."\">&nbsp;&nbsp;<input class=\"inpt01\" type=\"file\" name=\"document\" id=\"document\"></td>" .
		"</tr>\n");
echo("</table>");

echo(commandsHTML($aCmd));

echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
